import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../views/Login'
import Register from '../views/Register'
import Home from "@/views/Home.vue";
import FrontPage from "@/views/FrontPage.vue";
import HomeGoods from "@/views/HomeGoods.vue";
import HomePurchase from "@/views/HomePurchase.vue";
import HomeKnowledge from "@/views/HomeKnowledge.vue";
import KnowledgeDetail from "@/views/KnowledgeDetail.vue";
import HomeGuide from "@/views/HomeGuide.vue";
import guideDetail from "@/views/guideDetail.vue";
import AllExpert from "@/views/AllExpert.vue";
import question from "@/views/Question.vue";
import appointment from "@/views/Appointment.vue";
import ShopCart from "@/views/ShopCart.vue";
import UserPassword from "@/views/UserPassword.vue";
import User from "@/views/User.vue";
import UserInfo from "@/views/UserInfo.vue";
import UserAddress from "@/views/UserAddress.vue";
import PublishedGoods from "@/views/PublishedGoods.vue";
import PublishedNeeds from "@/views/PublishedNeeds.vue";
import expertQuestion from "@/views/expertQuestion.vue";
import expertAppoint from "@/views/expertAppoint.vue";
import PublishedKnowledges from "@/views/PublishedKnowledges.vue";
import UserBuy from "@/views/UserBuy.vue";
import UserSell from "@/views/UserSell.vue";
import PublishedNeedsAdmin from "@/views/PublishedNeedsAdmin.vue";
import PublishedGoodsAdmin from "@/views/PublishedGoodsAdmin.vue";
Vue.use(VueRouter)
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/register',
    component: Register
  },
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        component: Home,
        children: [
            {
                path: '',
                redirect: 'front'
            },
            {
                path: 'front',
                component: FrontPage
            },
            {
                path: 'goods',
                component: HomeGoods
            },
            {
                path: 'purchase',
                component: HomePurchase
            },
            {
                path: 'knowledge',
                component: HomeKnowledge
            },
            {
                path: 'knowledge/:id',
                component: KnowledgeDetail
            },
            {
                path: 'guide',
                component: HomeGuide
            },
            {
                path: 'guide/:id',
                component: guideDetail
            },
        ]
    },
    {
        path: 'allExpert',
        component: AllExpert
    },
    {
        path: 'question',
        component: question
    },
    {
        path: 'appointment',
        component: appointment
    },
    {
        path: 'shopcart',
        component: ShopCart
    },
    {
        path: 'user',
        component: User,
        children: [
            {
                path: '',
                redirect: 'userinfo'
            },
            {
                path: 'userinfo',
                component: UserInfo

            },
            {
                path: 'useraddress',
                component: UserAddress
            },
            {
                path: 'userpassword',
                component: UserPassword
            },
        ]
    },
    {
        path: 'publishedgoods',
        component: PublishedGoods
    },
    {
        path: 'publishedneeds',
        component: PublishedNeeds
    },
    {
        path: 'expertQuestion',
        component: expertQuestion
    },
    {
        path: 'expertAppoint',
        component: expertAppoint
    },
    {
        path: 'publishedknowledges',
        component: PublishedKnowledges
    },
    {
        path: 'userbuy',
        component: UserBuy
    },
    {
        path: 'usersell',
        component: UserSell
    },
    {
        path: 'publishedgoodsAdmin',
        component: PublishedGoodsAdmin
    },{
        path: 'PublishedNeedsAdmin',
        component: PublishedNeedsAdmin
    },
    {
        path: 'usermanage',
        component: UserManage
    },
]

 const router = new VueRouter({
  routes,
  mode: 'hash',
})
export default router